package com.data.center.service.impl;

import com.data.center.dictionary.NationalIdType;
import com.data.center.dto.PersonDto;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

//@SpringBootTest
@Slf4j
@SpringBootTest
class PersonServiceImplTestSC {

    @Autowired
    PersonServiceImpl personService;

    @Test
    void testChinese() {
        String name = "中国文字·";
        Pattern pattern = Pattern.compile("^[\u4e00-\u9fa5·]+$");
        Matcher matcher = pattern.matcher(name);
        Assert.assertEquals(matcher.matches(), true);

        name = "中国文字·sds";
        pattern = Pattern.compile("^[\u4e00-\u9fa5·]+$");
        matcher = pattern.matcher(name);
        Assert.assertEquals(matcher.matches(), false);

        name = "中国文字·**?132'";
        pattern = Pattern.compile("^[\u4e00-\u9fa5·]+$");
        matcher = pattern.matcher(name);
        Assert.assertEquals(matcher.matches(), false);

        name = "ASSDS SASD '---'ASD ";
        pattern = Pattern.compile("^[A-Za-z\\-' ]+$");
        matcher = pattern.matcher(name);
        Assert.assertEquals(matcher.matches(), true);

        // 将每个单词的首字母大写，其余字母小写
        String[] words = name.split("[\\-' ]");
        StringBuilder formattedName = new StringBuilder();
        for (String word : words) {
            if (!word.isEmpty()) {
                formattedName.append(word.substring(0, 1).toUpperCase())
                        .append(word.substring(1).toLowerCase()).append(" ");
            }
        }
        System.out.println(formattedName.toString().trim());


        System.out.println(NationalIdType.valueOf("居民身份证1"));
    }

    @Test
    void testAddPerson() {
        PersonDto personDtoMock = new PersonDto();
//        personDtoMock.setPersonId("mockedPersonId");
        personDtoMock.setName("mockedName");
        personDtoMock.setNationalIdType("居民身份证");
        personDtoMock.setNationalId("mockedNationalId");
        personDtoMock.setStid("mockedStid");
        personDtoMock.setGender("男");
        personDtoMock.setDob(new Date());
        personDtoMock.setEthnicGroup("汉族");
        personDtoMock.setNationality("中国");
        personDtoMock.setBirthplace("丰台区");
        personDtoMock.setPoliticalAffiliation("中国共产党党员");
        personDtoMock.setIdPhoto("mockedIdPhoto");
        personDtoMock.setLifePhoto("mockedLifePhoto");
        personDtoMock.setAffiliation("中国人民公安大学");
        personDtoMock.setDepartment("mockedDepartment");
        personDtoMock.setPositionRank("国家级正职");
        personDtoMock.setPosition("mockedPosition");
        personDtoMock.setTitle("高等学校教师");
        personDtoMock.setGraduation("中国人民公安大学");
        personDtoMock.setMajor("哲学");
        personDtoMock.setEducation("博士研究生");
        personDtoMock.setDegree("博士");
        personDtoMock.setDisciplines("物理学");
        personDtoMock.setCategory("mockedCategory");
        personDtoMock.setKeywords("mockedKeywords");
        personDtoMock.setDivision("丰台区");
        personDtoMock.setAddress("mockedAddress");
        personDtoMock.setPostCode("mockedPostCode");
        personDtoMock.setMobile("mockedMobile");
        personDtoMock.setFax("mockedFax");
        personDtoMock.setEmail("mockedEmail");
        personDtoMock.setPhone("mockedPhone");
        personDtoMock.setContactName("mockedContactName");
        personDtoMock.setContactMobile("mockedContactMobile");
        personDtoMock.setContactPhone("mockedContactPhone");
        personDtoMock.setAccount("mockedAccount");
        personDtoMock.setBank("mockedBank");
        personDtoMock.setBranch("mockedBranch");
        personDtoMock.setAccountOwner("mockedAccountOwner");
        personDtoMock.setAuthentication("mockedAuthentication");
        personDtoMock.setAuthenticator("mockedAuthenticator");

        log.info("personDtoMock" + personDtoMock.getNationalId());

        personService.addPerson(personDtoMock);
        // Now you have set values for all fields in the mock object.

    }
}